import request from '@/utils/request';
import { download, toFormData, checkDownloadRes } from '@/utils/common';

/**
 * 分页查询导出记录管理
 */
export async function pageEtpFileManagements(params) {
  const res = await request.get('/etp/etpFileManagement/list', { params });
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 查询全部导出记录管理
 */
export async function listEtpFileManagements(params) {
  const res = await request.get('/etp/etpFileManagement/list', { params });
  if (res.data.code === 200) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 根据id查询导出记录管理
 */
export async function getEtpFileManagement(id) {
  const res = await request.get('/etp/etpFileManagement/' + id);
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 添加导出记录管理
 */
export async function addEtpFileManagement(data) {
  const res = await request.post('/etp/etpFileManagement', data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 修改导出记录管理
 */
export async function updateEtpFileManagement(data) {
  const res = await request.put('/etp/etpFileManagement', data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 删除导出记录管理
 */
export async function removeEtpFileManagement(id) {
  const res = await request.delete('/etp/etpFileManagement/' + id);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 批量删除导出记录管理
 */
export async function removeEtpFileManagements(ids) {
  const res = await request.delete('/etp/etpFileManagement/' + ids.join());
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 导出导出记录管理
 */
export async function exportEtpFileManagements(params) {
  const res = await request({
    url: '/etp/etpFileManagement/export',
    method: 'POST',
    data: toFormData(params),
    responseType: 'blob'
  });
  await checkDownloadRes(res);
  download(res.data, `etpFileManagement_${Date.now()}.xlsx`);
}
